<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Title</title>
    <script>
        let yearSelect = null;
        let monthSelect = null;
        let daySelect = null;

        function setDayOption(year,month,day) {
            daySelect.innerHTML = "";
            daySelect.appendChild( new Option("==请选择==",-1) )
            if(year==-1||month==-1) return;
            let tempDay = new Date( year,month,0 );
            for (let i = 1; i <= tempDay.getDate(); i++) {
                daySelect.appendChild( new Option(`0${i}日`.substr(-3,3),i) );
                daySelect.value = day;
            }
        }
        "".substring()

        window.addEventListener("load",function (){
            yearSelect = document.querySelector("#year");
            monthSelect = document.querySelector("#month");
            daySelect = document.querySelector("#day");

            let d = new Date();
            yearSelect.appendChild( new Option("==请选择==",-1) )
            for (let i = d.getFullYear()-5; i <= d.getFullYear()+5; i++) {
                yearSelect.appendChild( new Option(i+"年",i) )
                yearSelect.value = d.getFullYear();
            }
            monthSelect.appendChild( new Option("==请选择==",-1) )
            for (let i = 1; i <= 12; i++) {
                // let text = `0${i}月`.substr(-3,3);
                let text = `0${i}月`;
                text = text.substring( text.length-3);
                monthSelect.appendChild( new Option(text,i) )
                monthSelect.value = d.getMonth()+1;
            }
            /*
            // 基于当前时间获取当前时间月分的最后一天
            //   月：d.getMonth()+1 => d.getMonth()获取当前月份[js月份 0~11]
            //                     => d.getMonth()+1 等于将月份向后推1个月
            //   日：0 => 设定当前月份的第 0 天，日最小值为 1
            //        =>  等同于将月份向前推1月，并取最后一天
            let tempDay = new Date( d.getFullYear(),d.getMonth()+1,0 );
            // console.log(tempDay.toLocaleString())
            daySelect.appendChild( new Option("==请选择==",-1) )
            for (let i = 1; i <= tempDay.getDate(); i++) {
                daySelect.appendChild( new Option(`0${i}日`.substr(-3,3),i) );
                daySelect.value = d.getDate();
            }
            */
            setDayOption(d.getFullYear(),d.getMonth()+1,d.getDate());
        })
        function resetDay(){
            let y =  Number.parseInt(yearSelect.value);
            let m =  Number.parseInt(monthSelect.value);
            setDayOption(y,m,-1)
        }
    </script>
</head>
<body>
    <select id="year" onchange="resetDay()"></select>
    <select id="month" onchange="resetDay()"></select>
    <select id="day"></select>
</body>
</html>